// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SongDisplayer.java

package presenter;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

// Referenced classes of package presenter:
//            SongFile, SongVerse

public class SongDisplayer extends JPanel
    implements MouseListener, KeyListener
{

    public SongDisplayer()
    {
        this(null);
    }

    public Component getPanel()
    {
        return scrollPane;
    }

    public SongDisplayer(SongFile sf)
    {
        super(new BorderLayout());
        active = 0;
        this.sf = sf;
        update = false;
        out = new JPanel();
        scrollPane = new JScrollPane();
        scrollPane.getViewport().setView(out);
        scrollPane.setVisible(true);
        add(scrollPane);
        out.setBackground(Color.WHITE);
        addKeyListener(this);
        setVisible(true);
    }

    public boolean isUpdating()
    {
        return update;
    }

    public SongFile getSong()
    {
        return sf;
    }

    public void setSong(SongFile sf)
    {
        this.sf = sf;
        SongVerse sv[] = sf.getVerses();
        verses = new JLabel[sv.length];
        out = new JPanel(new GridLayout(0, 1));
        out.setBackground(Color.WHITE);
        for(int i = 0; i < sv.length; i++)
        {
            verses[i] = new JLabel(sv[i].toString());
            out.add(verses[i]);
            verses[i].setHorizontalAlignment(0);
            verses[i].setOpaque(true);
            verses[i].setBackground(Color.WHITE);
            verses[i].addMouseListener(this);
        }

        length = sv.length;
        out.setSize(getWidth(), getHeight());
        scrollPane = new JScrollPane();
        scrollPane.getViewport().setView(out);
        scrollPane.setVisible(true);
        add(scrollPane, "Center");
    }

    public int getActive()
    {
        return active;
    }

    public boolean getUpdate()
    {
        if(update)
        {
            update = false;
            return true;
        } else
        {
            return false;
        }
    }

    public void setActive(int act)
    {
        if(active >= 0 && active < length)
            verses[active].setBackground(Color.WHITE);
        verses[act].setBackground(Color.BLUE);
        active = act;
    }

    public void mouseClicked(MouseEvent mouseevent)
    {
    }

    public void mousePressed(MouseEvent me)
    {
        requestFocusInWindow();
        if(active >= 0 && active < length)
            verses[active].setBackground(Color.WHITE);
        for(int i = 0; i < verses.length; i++)
            if(me.getSource() == verses[i])
            {
                verses[i].setBackground(Color.BLUE);
                active = i;
            }

        if(me.getClickCount() == 2)
        {
            update = true;
            for(int i = 0; i < verses.length; i++)
                if(verses[i] != me.getSource());

        }
    }

    public void mouseReleased(MouseEvent mouseevent)
    {
    }

    public void mouseEntered(MouseEvent mouseevent)
    {
    }

    public void mouseExited(MouseEvent mouseevent)
    {
    }

    public void keyTyped(KeyEvent keyevent)
    {
    }

    public void keyPressed(KeyEvent ke)
    {
        int x = ke.getModifiers();
        int key = ke.getKeyCode();
        if(x == 0 && key == 38 && active > 0)
            setActive(active - 1);
        if(x == 0 && key == 40 && active < length - 1)
            setActive(active + 1);
    }

    public void keyReleased(KeyEvent keyevent)
    {
    }

    SongFile sf;
    JLabel verses[];
    JPanel out;
    JScrollPane scrollPane;
    boolean update;
    int active;
    int length;
}
